package com.yuanwu.ncs.rabbitmq;

import com.rabbitmq.client.Channel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class Consumer {

    @Value("${server.port}")
    private Integer port;

    @Resource
    private Environment environment;

    @RabbitListener(queues = "${msg.consumer.queue}")
    public void msgSend(Object msg, Message message, Channel channel) {
        String queueName = environment.getProperty("msg.consumer.queue");
        log.info("queueName:{}", queueName);
        log.info("消费者收到消息:{}  port:{}", msg, port);
    }
}
